package nothing.dao.hibernate;

import nothing.Util;
import nothing.model.Purchase;
import nothing.dao.PurchaseDao;
import org.appfuse.dao.hibernate.GenericDaoHibernate;

import java.math.BigDecimal;
import java.util.List;

public class PurchaseDaoHibernate extends GenericDaoHibernate<Purchase, Long> implements PurchaseDao {

    public PurchaseDaoHibernate() {
        super(Purchase.class);
    }

    @SuppressWarnings("unchecked")
    public List<Purchase> findByFoodName(String name){        
    	List<Object[]> mess = getHibernateTemplate().find(
    			"from Purchase p, Food f where p.food=f and f.name=? order by p.when", name);
    	return Util.toList(mess,0);
    }

    @SuppressWarnings("unchecked")
    public List<Purchase> findByCost(BigDecimal cost) {
        return getHibernateTemplate().find("from Purchase where cost=?", cost);
    }
}
